package com.frxuexi.park

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ParkViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<ParkIntent>(){
    override fun handleIntent(it: ParkIntent) {
        when(it){
            is ParkIntent.getParksByType->httpRequest(apiService.getParksByType(it.type))
            is ParkIntent.deletePark->httpRequest(apiService.deletePark(it.id),RequestType.DELETE)
            is ParkIntent.getParksByArea->httpRequest(apiService.getParksByArea(it.area),RequestType.AREA)
            is ParkIntent.getParksByCarNo->httpRequest(apiService.getParksByCarNo(it.carNo),RequestType.CARNO)
            is ParkIntent.getParksByStatus->httpRequest(apiService.getParksByStatus(it.status),RequestType.PARKSTATUS)
            is ParkIntent.addPark->httpRequest(apiService.addPark(toBody(it.item)),RequestType.ADD)
            is ParkIntent.getParkById->httpRequest(apiService.getParkById(it.id))
            is ParkIntent.updatePark->httpRequest(apiService.updatePark(it.id,toBody(it.item)),RequestType.UPDATE)
            is ParkIntent.updateParkStatus->httpRequest(apiService.updateParkStatus(it.id,it.status),RequestType.UPDATE)
        }
    }
}